package com.wangzeqi.changliaoba.singleton;

import android.graphics.Bitmap;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

/**
 * Created by dllo on 16/3/8.
 */
public class MyMemoryCache implements ImageLoader.ImageCache{
    private LruCache<String,Bitmap> cache;

    public MyMemoryCache() {
        int maxMemory = (int) (Runtime.getRuntime().maxMemory()/1024);
        int cacheSize =  (maxMemory/4);
        cache = new LruCache<String,Bitmap>(cacheSize){
            @Override
            protected int sizeOf(String url, Bitmap bitmap) {
                return bitmap.getRowBytes()*bitmap.getHeight()/1024;
            }
        };


    }

    @Override
    public Bitmap getBitmap(String url) {
//        if(url.contains(".jpg")){

            return cache.get(url);
//        }else {
//            return null;
//        }
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
//        if(url.contains(".jpg")){

            cache.put(url,bitmap);
//        }
    }
}
